<template>
  <view v-if="isMembershipInfoPage" class="download-applytable">
    <view class="download-item ml-4 mb-24">
      <view class="disFlxAC mb-8">
        <view class="download-title mr-8">
          <text>下载{{ getShowName }}</text>
        </view>
        <TButton
          type="primary"
          text="立即下载"
          :customStyle="{
            width: 'fit-content',
            borderRadius: '32rpx',
            height: '64rpx',
            lineHeight: '64rpx',
            padding: '0 32rpx',
          }"
          @click="downloadFile"
        />
      </view>
      <view class="tips">
        <text>下载填写的{{ getShowName }}，打印盖章</text>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
  import TButton from '@/components/TButtonGroup/TButton.vue';
  import { useFormItem } from '../hooks/useContext';
  import { computed } from 'vue';
  import { Pages } from '@/router/types/pages';
  import { useUpload } from '@/hooks/core/useUpload';
  import { Api } from '@/api/membership';
  import { useEnv } from '@/hooks/core/useEnv';

  const { FormItem } = useFormItem({});
  const { openDocument } = useUpload();
  const { getEnv } = useEnv();

  const pages = getCurrentPages();
  const isMembershipInfoPage = pages[pages.length - 1].route === Pages.membershipInfo;

  const getShowName = computed(() => {
    return FormItem?.getValues.value.schema.label;
  });

  function downloadFile() {
    openDocument({
      filePath: getEnv('BASE_URL') + Api.memberApplyFormPdf,
      fileType: 'pdf',
      customFileName: getShowName.value,
    });
  }
</script>

<style lang="scss" scoped>
  .download-item {
    .download-title {
      font-size: 28rpx;
      color: #333;
    }
    .tips {
      font-size: 24rpx;
      color: #999996;
    }
  }
</style>
